package com.cmol.peopledetectapp.user;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.cmol.data.GlobalData;
import com.cmol.data.SettingData;
import com.cmol.peopledetectapp.R;

/**
 * 地图展示场景选择界面
 *
 * @author 张瀚文
 */
public class MapActivity extends AppCompatActivity {

    private Button mapButton, listButton, personButton, placeButton1, placeButton2;
    private ImageView imageView;
    private long exitTime = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);

        mapButton = findViewById(R.id.button3);
        listButton = findViewById(R.id.button4);
        personButton = findViewById(R.id.PersonButton2);
        placeButton1 = findViewById(R.id.PlaceButton1);
        placeButton2 = findViewById(R.id.PlaceButton2);
        imageView = findViewById(R.id.imageView30);

        // 系统设置
        SystemSetting();
    }

    // 按两次返回才退出
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
            if ((System.currentTimeMillis() - exitTime) > 2000) {
                Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show();
                exitTime = System.currentTimeMillis();
            } else {
                finish();
                System.exit(0);
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    // 跳转至列界面
    public void ListClick(View view) {
        startActivity(new Intent(this, ListLocationActivity.class));
        finish();
    }

    // 跳转至个人界面
    public void PersonClick(View view) {
        startActivity(new Intent(this, PersonalActivity.class));
        finish();
    }

    // 跳转至启翔楼场景（场景一）
    public void TushuguanDetailClick(View view) {
        // 设置当前场景编号为 1
        GlobalData.setCurrentSceneID(1);
        startActivity(new Intent(this, DetailActivity.class));
    }

    // 系统设置函数
    private void SystemSetting() {
        if (SettingData.getCOLOR() == false) {
            imageView.setBackgroundColor(0x3857be);
            personButton.setBackgroundResource(R.drawable.ic_baseline_redengineering_24);
            listButton.setBackgroundResource(R.drawable.ic_baseline_redclear_all_24);
            mapButton.setBackgroundResource(R.drawable.ic_baseline_redlocation_on_24);
            placeButton1.setBackgroundResource(R.drawable.ic_baseline_my_redlocation_24);
            placeButton2.setBackgroundResource(R.drawable.ic_baseline_my_redlocation_24);
        } else {
            imageView.setBackgroundColor(0xa7e2ff);
            personButton.setBackgroundResource(R.drawable.ic_baseline_engineering_24);
            listButton.setBackgroundResource(R.drawable.ic_clear_all_black_24dp);
            mapButton.setBackgroundResource(R.drawable.ic_place_black_24dp);
            placeButton1.setBackgroundResource(R.drawable.ic_my_location_black_24dp);
            placeButton2.setBackgroundResource(R.drawable.ic_my_location_black_24dp);
        }
    }
}
